package com.zheng.study.base.bean.search.result;

import com.zheng.study.base.bean.search.Search;
import org.springframework.util.Assert;

/**
 * 查询 - 结果 - SearchResultUnique
 * ============================================================================
 * author : fallenpanda
 * createDate:  2018/6/12 。
 * ============================================================================
 */
public class SearchResultUnique extends SearchResult {

	private final Object object;

	public SearchResultUnique(Search search, Object object) {
		super(search);
		this.object = object;
	}

	public Object getObject() {
		return object;
	}

	public static SearchResultUnique uniqueResult(Search search, Object object){
		return newBuilder().setSearch(search).setObject(object).build();
	}

	public static Builder newBuilder(){
		return new Builder();
	}

	private static class Builder extends SearchResult.Builder<SearchResult, Builder>{

		private Object object;

		public Builder setObject(Object object) {
			this.object = object;
			return this;
		}

		@Override
		protected Builder getThis() {
			return this;
		}

		@Override
		public SearchResultUnique build() {
			Assert.notNull(search, "search 不能为空");
			return new SearchResultUnique(search, object);
		}
	}

}
